package com.zbkj.dal.base.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;

/**
 * 参数输入类型
 * @author tianzhonghai
 * 2023/11/1 08:21
 */
@Getter
@AllArgsConstructor
public enum ParameterInputTypeEnum {

    TEXT("text", "文本", false, true),
    RADIO("radio", "单选", true, true),
    CHECKBOX("checkbox", "多选", true, false),;

    private final String type;
    private final String name;
    private final Boolean needOption;
    private final Boolean singleValue;

    public static String getNameByType(String type) {
        return Arrays.stream(ParameterInputTypeEnum.values()).filter(p -> ObjectUtils.nullSafeEquals(type, p.getType()))
                .map(m -> m.getName()).findFirst().orElse("");
    }

    public static boolean supportOption(String type) {
        return Arrays.stream(ParameterInputTypeEnum.values()).filter(p -> ObjectUtils.nullSafeEquals(type, p.getType()))
                .map(m -> m.getNeedOption()).findFirst().orElse(false);
    }

    public static boolean singleValue(String type) {
        return Arrays.stream(ParameterInputTypeEnum.values()).filter(p -> ObjectUtils.nullSafeEquals(type, p.getType()))
                .map(m -> m.getSingleValue()).findFirst().orElse(false);
    }
}
